package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.PersonBase.DiseaseBean;
import com.project.mapper.IDiseaseMapper;
import com.project.service.IDiseaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class IDiseaseServiceImpl extends ServiceImpl<IDiseaseMapper,DiseaseBean> implements IDiseaseService {
    @Override
    public IPage<DiseaseBean> findDisease(int pageNo, int pageSize, String diseaseName, String diseaseSymptom) {

        Page<DiseaseBean> page = new Page<>(pageNo,pageSize);

        QueryWrapper wrapper = new QueryWrapper<>();

        if (diseaseName != null){
            wrapper.like("disease_name",diseaseName);
        }

        if (diseaseSymptom != null){
            wrapper.like("disease_symptom",diseaseSymptom);
        }

        IPage<DiseaseBean> diseaseBeanIPage = this.baseMapper.selectPage(page,wrapper);

        return diseaseBeanIPage;
    }

    @Override
    public void addDisease(DiseaseBean diseaseBean) {

        this.baseMapper.insert(diseaseBean);

    }

    @Override
    public DiseaseBean findDiseaseById(int diseaseId) {


        return this.baseMapper.selectById(diseaseId);


    }
}
